package com.cn.xcsharp.service;

import com.cn.xcsharp.bean.PagingBean;
import com.cn.xcsharp.util.PagingUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Repository
public class PublicDataServiceImpl implements IPublicDataService {
    //导入JDBCTemplate模板
//    @Resource
//    private JdbcTemplate jdbcTemplate;
    @Resource(name = "jdbcTemplateOrcle")
    JdbcTemplate jdbcTemplateOrcle;
    @Override
    public int insertDB(String sql) {
        return  jdbcTemplateOrcle.update(sql);
    }

    @Override
    public int updateDB(String sql) {
        return  jdbcTemplateOrcle.update(sql);
    }

    @Override
    public int deleteDB(String sql) {
        return  jdbcTemplateOrcle.update(sql);
    }

    @Override
    public List getList(String sql, Object... params) {
        List<Map<String, Object>> list = null;
        try {
            list = jdbcTemplateOrcle.queryForList(sql, params);
        } catch (DataAccessException e) {
            e.printStackTrace();
            list = new ArrayList<>();
        }
        return list;
    }

    @Override
    public PagingBean getListFy(String sql, int pageNo, int pageSize, Object... params) {
        PagingBean pagingBean=new PagingBean();
        pagingBean= PagingUtils.getJdbcPage(sql,pageNo,pageSize,jdbcTemplateOrcle,params);
        return pagingBean;
    }
}
